package com.huang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huang.dto.MenuRoleDto;
import com.huang.entity.Menu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author han
 * @since 2022-01-16 18:59:49
 */
@Mapper
public interface MenuDao extends BaseMapper<Menu> {

    @Select("<script>" +
            "select a.* from sys_menu as a, sys_menu_role as b where a.id = b.menu_id and b.role_id in " +
            "<foreach collection=\"roleIds\" item=\"item\" separator=\",\" open=\"(\" close=\")\">" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<Menu> findByRoleIds(@Param("roleIds") List<String> roleIds);

    @Select("<script>" +
            "SELECT b.url as url, c.`code` as roleCode from sys_menu_role as a, " +
            "sys_menu as b, sys_role as c " +
            "WHERE a.menu_id = b.id and a.role_id = c.id" +
            "</script>")
    List<MenuRoleDto> findUrlAndRole();
}
